package com.meusconcursos;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Toast;

import com.meusconcursos.dto.Edital;

public class EditalListActivity extends ListActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_edital);
		setTitle(R.string.titulo_lista_edital);

		ArrayAdapter<Edital> adapter = new ArrayAdapter<Edital>(this,
				android.R.layout.simple_list_item_1,
				MeusConcursosActivity.dbHelper.getEditais());
		setListAdapter(adapter);

		this.getListView().setOnItemClickListener(
				new AdapterView.OnItemClickListener() {

					@Override
					public void onItemClick(AdapterView<?> parentView,
							View childView, int position, long id) {

						Edital edital = (Edital) parentView
								.getItemAtPosition(position);

						Intent intent = new Intent(getBaseContext(),
								CargoListActivity.class);

						intent.putExtra("id_edital", edital.getId());

						startActivity(intent);

					}
				});

		this.getListView().setOnItemLongClickListener(
				new AdapterView.OnItemLongClickListener() {

					@Override
					public boolean onItemLongClick(AdapterView<?> parentView,
							View childView, int position, long id) {

						Edital edital = (Edital) parentView
								.getItemAtPosition(position);

						Toast.makeText(getBaseContext(), edital.getNomeOrgao(),
								Toast.LENGTH_LONG).show();

						return false;
					}

				});

	}

}
